package com.gears_software.sxdc.dccx.data.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.gears_software.sxdc.dccx.data.model.Cities;
import com.gears_software.sxdc.dccx.data.model.LineInfoModel;
import com.gears_software.sxdc.dccx.ui.view.HotCitiesItemView;
import com.gears_software.sxdc.dccx.ui.view.HotCitiesItemView_;

import java.util.List;

/**
 * Created by SunMuran on 2017/7/22.
 * 热门城市的adapter
 */

public class HotCitiesAdapter extends BaseAdapter {
    private Context context;
    private List<LineInfoModel> citiesData;

    public HotCitiesAdapter(Context context, List<LineInfoModel> citiesData) {
        this.context = context;
        this.citiesData = citiesData;
    }

    public void updateHotCites(List<LineInfoModel> cities){
        citiesData = cities;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return citiesData.size();
    }

    @Override
    public LineInfoModel getItem(int position) {
        return citiesData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HotCitiesItemView citiesItemView = null;
        if (convertView == null) {
            citiesItemView = HotCitiesItemView_.build(context);
        } else {
            citiesItemView = (HotCitiesItemView) convertView;
        }
        citiesItemView.bind(citiesData.get(position));
        return citiesItemView;
    }

    // class ViewHolder{
    //   TextView tvCity;
    //}
}
